// pages/logistics/logistics.js
const {
  orderById,
  orderLogistics
  // imageBaseUrl
} = require('../../api/url.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: {},
    logistic: {},
    logisticList: [{
        img: "../../imgs/logistic/tiantian.jpg",
        name: "天天快递",
        tel: "400-188-8888"
      },
      {
        img: "../../imgs/logistic/shentong.jpg",
        name: "申通快递",
        tel: "95543"
      },
      {
        img: "../../imgs/logistic/yunda.jpg",
        name: "韵达快递",
        tel: "95546"
      },
      {
        img: "../../imgs/logistic/yuantong.jpg",
        name: "圆通快递",
        tel: "95554"
      },
      {
        img: "../../imgs/logistic/zhongtong.jpg",
        name: "中通快递",
        tel: "95311"
      },
      {
        img: "../../imgs/logistic/shunfeng.jpg",
        name: "顺丰快递",
        tel: "95338"
      },
      {
        img: "../../imgs/logistic/baishi.jpg",
        name: "百世汇通",
        tel: "95320"
      },
      {
        img: "../../imgs/logistic/cainiao.png",
        name: "飞鸟驿站",
        tel: "4001787878"
      },
    ]
  },
  loadLogistics(id) {
    wx.showLoading({
      title: '加载中',
    })
    const {
      user
    } = this.data
    var self = this
    wx.request({ //根据订单里id查询订单对应物流信息
      url: orderLogistics,
      data: {
        fOrderId: id,
        token: wx.getStorageSync("token"),
        loginName: user.loginname,
        fUserId: user.id
      },
      success: function(res) {
        if (res.data.code == 403) {
          wx.hideLoading()
        } else if (res.data.code == 1) {
          wx.hideLoading()
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        } else if (res.data.code == 0) {
          wx.hideLoading()
          var logistic = res.data.response.cont
          for (var i = 0; i < self.data.logisticList.length; i++) {
            if (logistic.fPostName == self.data.logisticList[i].name) {
              logistic.postImg = self.data.logisticList[i].img
              logistic.postTel = self.data.logisticList[i].tel
            }
          }
          self.setData({
            logistic: logistic || []
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      user: app.globalData.userInfo
    })
    if (options.id) {
      this.loadLogistics(options.id)
    }
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})